package com.zoro.dyformservice.business.user.repository;

import com.zoro.dyformservice.business.user.entity.UserInfoEntity;
import com.zoro.dyformservice.constants.response.common.YesOrNo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface UserRepository extends JpaRepository<UserInfoEntity, String>, JpaSpecificationExecutor<UserInfoEntity> {
    UserInfoEntity findByUserId(String userId);

    @Query("select t from UserInfoEntity t where t.userName  like %?#{[0]}%")
    List<UserInfoEntity> findByUserNameLike(String userName);

    @Transactional
    @Modifying
    @Query("update UserInfoEntity t set t.deleted = :deleted where t.userId = :id")
    int updateDeleted(@Param("id") String id, @Param("deleted") YesOrNo deleted);
}
